﻿#region 信息

// Copyright©2014 Rex Rao all rights reserved.
// File name : SoMcCoffee\Sohobloo.SoCommon\NullExtension.cs
// Author : Sohobloo
// Create time : 2014/01/31 23:40
// Update time : 2014/02/05 8:54

#endregion

#region 引用

using System.Collections;

#endregion

namespace Sohobloo.SoCommon.CommonExtension
{
    public static class NullExtension
    {
        public static bool IsNull(this object value)
        {
            return value == null;
        }

        public static bool IsNotNull(this object value)
        {
            return !value.IsNull();
        }

        public static bool IsNullOrEmpty(this ICollection collection)
        {
            return collection.IsNull() || collection.Count == 0;
        }

        public static bool IsNotNullOrEmpty(this ICollection collection)
        {
            return !collection.IsNullOrEmpty();
        }

        public static bool IsNullOrEmpty(this string value)
        {
            return string.IsNullOrWhiteSpace(value);
        }

        public static bool IsNotNullOrEmpty(this string value)
        {
            return !value.IsNullOrEmpty();
        }

        public static string NullToEmpty(this string arg)
        {
            return arg ?? string.Empty;
        }

        public static T NullToEmpty<T>(this T arg) where T : ICollection, new()
        {
            return arg.IsNull() ? new T() : arg;
        }
    }
}